package text.excel;

import cn.main.utils.DataUtils;
import cn.main.utils.ExcelUtil;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import sun.org.mozilla.javascript.internal.IdFunctionCall;


import java.io.*;
import java.sql.Time;
import java.util.*;

/**
 * Author: chengwei
 * Date:   2016/9/7
 * Time:   15:22
 */
public class TestExcel {
   

    public static void main(String[] args) {
        Map<String,String> fieldName = new LinkedHashMap<>();
        fieldName.put("id","ID");
        fieldName.put("name","姓名");
        fieldName.put("date","日期");
        fieldName.put("age","年龄");
        fieldName.put("marry","婚否");
        fieldName.put("time","时间");
        DataExcelExport export = new DataExcelExport();
        export.setFieldName(fieldName);
        List<Map<String,Object>> data = new ArrayList<>();
        Map<String,Object> row = new HashMap<>();
        row.put("id","001");
        row.put("name","张");
        row.put("date",new Date());
        row.put("marry",(byte)1);
        row.put("time",Time.valueOf("10:30:00"));
        data.add(row);
        row = new HashMap<>();
        row.put("id","001");
        row.put("name","俪");
        row.put("date",new Date(new Date().getTime() - 1000000));
        data.add(row);
        row = new HashMap<>();
        row.put("id","001");
        row.put("name","孙");
        row.put("date",new Date(new Date().getTime() + 1000000));
        row.put("marry",true);
        data.add(row);
        row = new HashMap<>();
        row.put("id","001");
        row.put("name","wang");
        row.put("date",new Date(new Date().getTime() + 2000000));
        row.put("marry","001");
        row.put("age",20);
        data.add(row);
        export.setDataList(data);
        File file = new File("E:\\MyDownloads\\Download\\测试一下1.xlsx");
        int index = 1;
//        while (file.exists()) {
////            file = new File("E:\\MyDownloads\\Download\\测试一下_" + (index ++) +".xls");
//        }
//        exportExcel(export,file);
//        file = new File("E:\\MyDownloads\\Download\\测试一下.xls");
//        exportExcel(export,file);

        System.out.println(ExcelUtil.importExcel(export,file));
    }
}
